﻿using Microsoft.EntityFrameworkCore;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace DFGK_WMS.Model.Models
{
    /// <summary>
    /// 入库单明细
    /// </summary>
    [SugarTable(tableName: "TReceivingOrderDetailS")]
    public partial class TReceivingOrderDetail
    {
        /// <summary>
        /// 明细Id
        /// </summary>
        [SugarColumn(IsPrimaryKey =true)]
        public int Id { get; set; }
        /// <summary>
        /// 入库单编号
        /// </summary>
        public string OrderSn { get; set; }

        /// <summary>
        /// 单据类型
        /// </summary>
        public int? BillType { get; set; }
        /// <summary>
        /// 库房编码
        /// </summary>
        public string WarehouseCode { get; set; }
        /// <summary>
        /// 库房名称
        /// </summary>
        public string WarehouseName { get; set; }
        /// <summary>
        /// 库区编码
        /// </summary>
        public string AreaCode { get; set; }
        /// <summary>
        /// 库区名称
        /// </summary>
        public string AreaName { get; set; }
        /// <summary>
        /// 物料Id
        /// </summary>
        public int? MaterialId { get; set; }
        /// <summary>
        /// 物料号
        /// </summary>
        public string MaterialCode { get; set; }
        /// <summary>
        /// 物料名称
        /// </summary>
        public string MaterialName { get; set; }
        /// <summary>
        /// 物料类型编码
        /// </summary>
        public string MaterialTypeCode { get; set; }
        /// <summary>
        /// 物料类型
        /// </summary>
        public string MaterialTypeName { get; set; }
        /// <summary>
        /// 实际接收数量：为基本单位的数量
        /// </summary>
        public decimal? ReceivedQty { get; set; }
        /// <summary>
        /// 期待数量：即订单数量，为基本单位的数量
        /// </summary>
        public decimal? Qty { get; set; }
        /// <summary>
        /// 码垛完成的数量
        /// </summary>
        public decimal? StackedQty { get; set; }
        /// <summary>
        /// 包装完成的数量
        /// </summary>
        public decimal? PackagedQty { get; set; }
        /// <summary>
        /// 总包装数量
        /// </summary>
        public int? PackQty { get; set; }
        /// <summary>
        /// 物料基本单位Id
        /// </summary>
        public int? UnitId { get; set; }
        /// <summary>
        /// 物料基本单位
        /// </summary>
        public string UnitName { get; set; }
        /// <summary>
        /// ERP物料号
        /// </summary>
        public string Erpcode { get; set; }
        /// <summary>
        /// 批次号
        /// </summary>
        public string BatchNo { get; set; }
        /// <summary>
        /// 有效期
        /// </summary>
        public DateTime? ExpireDate { get; set; }
        /// <summary>
        /// 质检日期
        /// </summary>
        public DateTime? Qadate { get; set; }
        /// <summary>
        /// 生产日期
        /// </summary>
        public DateTime? ProductDate { get; set; }
        /// <summary>
        /// 生产厂家
        /// </summary>
        public string ProduceFactory { get; set; }
        /// <summary>
        /// 供应商Id
        /// </summary>
        public int? SupplierId { get; set; }
        /// <summary>
        /// 供应商
        /// </summary>
        public string SupplierName { get; set; }
        /// <summary>
        /// 出厂日期
        /// </summary>
        public DateTime? OutFactoryDate { get; set; }
        /// <summary>
        /// 货主Id
        /// </summary>
        public int? OwnerId { get; set; }
        /// <summary>
        /// 货主
        /// </summary>
        public string OwnerName { get; set; }
        /// <summary>
        /// 最早入库时间
        /// </summary>
        public DateTime? InStarDate { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateDate { get; set; }

        /// <summary>
        /// 物料Key
        /// </summary>
        public int? MaterialKeyId { get; set; }
        /// <summary>
        /// 质量状态：0-待检；1-合格；2-不合格；
        /// </summary>
        public int QualityState { get; set; }
        /// <summary>
        /// 状态：0-新建;1-已启动;2-作业中;3-已完成;4-强制完成;5-暂停;6-失效；7-异常
        /// </summary>
        public int Status { get; set; } = 0;
        public string MaterialImg { get; set; }
        /// <summary>
        /// 逻辑分区编码
        /// </summary>
        public string LogicalPartCode { get; set; }
        /// <summary>
        /// 逻辑分区名称
        /// </summary>
        public string LogicalPartName { get; set; }
        /// <summary>
        /// 物料凭证号
        /// </summary>
        public string Mblnr { get; set; }
        /// <summary>
        /// 部门编码
        /// </summary>
        public string DeptCode { get; set; }
        /// <summary>
        /// 部门名称
        /// </summary>
        public string DeptName { get; set; }
        /// <summary>
        /// 合同号
        /// </summary>
        public string ContractNo { get; set; }
        /// <summary>
        /// 单据来源类型：0-手动建单；1-ERP;2-MES;3-SAP
        /// </summary>
        public int? SourceType { get; set; }
        /// <summary>
        /// 创建人Id
        /// </summary>
        public int? CreateUserId { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        public string CreateUserName { get; set; }
        /// <summary>
        /// 修改人Id
        /// </summary>
        public int? ModifyUserId { get; set; }
        /// <summary>
        /// 修改人
        /// </summary>
        public string ModifyUserName { get; set; }
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? ModifyDate { get; set; }
        /// <summary>
        /// 提交时间
        /// </summary>
        public DateTime? SubmitDate { get; set; }
        /// <summary>
        /// 提交人Id
        /// </summary>
        public int? SubmitUserId { get; set; }
        /// <summary>
        /// 提交人
        /// </summary>
        public string SubmitUserName { get; set; }
        /// <summary>
        /// 审核人Id
        /// </summary>
        public int? AuditUserId { get; set; }
        /// <summary>
        /// 审核人
        /// </summary>
        public string AuditUserName { get; set; }
        /// <summary>
        /// 审核时间
        /// </summary>
        public DateTime? AuditDate { get; set; }
        /// <summary>
        /// 物料凭证年度
        /// </summary>
        public string Mjahr { get; set; }
        /// <summary>
        /// 物料凭证行项目
        /// </summary>
        public string Zeile { get; set; }
        /// <summary>
        /// 采购订单号
        /// </summary>
        public string PurOrderNo { get; set; }
        /// <summary>
        /// 采购订单行号
        /// </summary>
        public string PurOrderLineNo { get; set; }
        /// <summary>
        /// 采购订单行项目类型：0-无；1-L外协；2-U转储;3-正常采购
        /// </summary>
        public int? PurOrderLineType { get; set; }
        /// <summary>
        /// 生产订单号
        /// </summary>
        public string ProOrderNo { get; set; }
        /// <summary>
        /// 外协需求跟踪号
        /// </summary>
        public string OutOrderNo { get; set; }

        /// <summary>
        /// 关联入库凭据Id
        /// </summary>
        public int? RefInVoucherId { get; set; }

        /// <summary>
        /// 仓库Id
        /// </summary>
        public int? WarehouseId { get; set; }

        /// <summary>
        /// 库位
        /// </summary>
        public string storeLocationId { get; set; }

        /// <summary>
        /// 关联的验收单明细项Id
        /// </summary>
        public int relationId { get; set; }

        /// <summary>
        /// 收货明细Id
        /// </summary>
        public int? ReceivingBillDetailId { get; set; }

        /// <summary>
        /// 收货明细Id
        /// </summary>
        public int? ReceivingBillId { get; set; }

        /// <summary>
        /// 总计
        /// </summary>
        public decimal? TotalPrice { get; set; }

        /// <summary>
        /// 单价
        /// </summary>
        public decimal? Price { get; set; }

        /// <summary>
        /// 批次号说明
        /// </summary>
        public string? BatchNoExplain { get; set; }

        /// <summary>
        /// 当前登陆人Id
        /// </summary>
        [NotMapped]
        [SugarColumn(IsIgnore =true)]
        public int NowUserId { get; set; }

        /// <summary>
        /// 当前登陆人真实姓名
        /// </summary>
        [NotMapped]
        [SugarColumn(IsIgnore = true)]
        public string NowUserRealName { get; set; }

        /// <summary>
        /// 进度
        /// </summary>
        [NotMapped]
        [SugarColumn(IsIgnore = true)]
        public decimal ProgressValue
        {
            get
            {
                if (this.ReceivedQty <= 0 || this.Qty<= 0)
                {
                    return 0;
                }
                decimal val = Math.Truncate(this.ReceivedQty.GetValueOrDefault() * 1000.0M / this.Qty.GetValueOrDefault()) / 10;
                if (val > 100)
                {
                    val = 100;
                }
                return val;
            }
        }
    }
}
